
class MyBlockingQueue{
    private String[] data=new String[1000];
    private volatile int head=0;
    private volatile int tail=0;
    private volatile int size=0;//有效元素个数

    public synchronized void put(String elem) throws InterruptedException {
            while(size== data.length){
                    this.wait();
            }
            data[tail]=elem;
            tail++;
            if(tail== data.length){
                tail=0;
            }
            size++;
            this.notify();
    }

    public synchronized String take() throws InterruptedException{
            while (size==0){
               this.wait();
            }
            String ret=data[head];
            head++;
            if(head== data.length){
                head=0;
            }
            size--;
            this.notify();
            return ret;
    }
}

public class demo11 {
    public static void main(String[] args) {

    }
}
